//
//  PMDownloadModel+ZYVideo.m
//  JW_BasePorject
//
//  Created by JW on 2018/6/30.
//  Copyright © 2018年 JW. All rights reserved.
//

#import "PMDownloadModel+ZYVideo.h"
//#import "DownloadVideoModel.h"
@implementation PMDownloadModel (ZYVideo)

@dynamic course_name;
@dynamic chapter_name;
@dynamic section_name;
@dynamic indexID;
@dynamic zy_videoSize;

//- (DownloadVideoModel *)videoInfo{
//    DownloadVideoModel *videoInfo = [DownloadVideoModel mj_objectWithKeyValues:self.showFileName];
//    // 转换为JSON 字符串
//    //    NSString *showFileName = videoInfo.mj_JSONString;
//    return videoInfo;
//}


- (NSString *)course_name{
    NSString * courseName = [self.showFileName componentsSeparatedByString:@"-"][0];
    return courseName;
}

- (NSString *)chapter_name{
    NSString * chapterName = [self.showFileName componentsSeparatedByString:@"-"][1];
    return chapterName;
}

- (NSString *)section_name{
    NSString * sectionName = [self.showFileName componentsSeparatedByString:@"-"][2];
    return sectionName;
}

- (NSInteger)indexID{
    if ([self.showFileName componentsSeparatedByString:@"-"].count > 3) {
        NSString * index = [[self.showFileName componentsSeparatedByString:@"-"] objectAtIndex:3];
        return [index integerValue];
    }else{
        
        return 0;
    }
    
}


- (NSString *)zy_videoSize{
    float size = self.totalLength;
    if(size >=1024*1024)//大于1M，则转化成M单位的字符串
    {
        return [NSString stringWithFormat:@"%1.2fM",size/1024/1024];
    }
    else if(size >=1024 && size<1024*1024) //不到1M,但是超过了1KB，则转化成KB单位
    {
        return [NSString stringWithFormat:@"%1.2fK",size /1024];
    }
    else//剩下的都是小于1K的，则转化成B单位
    {
        return [NSString stringWithFormat:@"%1.2fB",size];
    }
}

@end
